module TasksHelper
  
  def tree_ul(acts_as_tree_set, init=true, &block)
    if acts_as_tree_set.size > 0
      ret = '<ul>'
      acts_as_tree_set.collect do |item|
        next if item.parent_id && init
        ret += '<li>'
        ret += yield item
        ret += tree_ul(item.children, false, &block) if item.children.size > 0
        ret += '</li>'
      end
      ret += '</ul>'
    end
  end
  
  def over_estimate(estimate, actual)
    if actual.to_f > estimate.to_f
      "<font color='red'>#{actual}</font>"
    else
      actual
    end
  end
  
  # In certain phases users should be let to enter work reports, which are hours.
  def can_enter_working_unit?(status)
    status_for_work_unit_entry = { 'In Progress' => 'In Progress',
      'In Revision' => 'In Revision'}
    status_for_work_unit_entry.detect {|key, value| value == status }  ? true : false
  end

end